package model;

import java.io.Serializable;
import java.util.ArrayList;

public class PlayerGameStats implements PlayerGameStatsInterface, Serializable
{
	private double averageWinLoss;
	
	private int totalWinLoss;
	
	private int playedRounds;
	
	private int roundWinnings;
	
	private ArrayList<GameRoundStats> roundStats;
	
	PlayerGameStats()
	{
		roundStats = new ArrayList<GameRoundStats>();
	}
	
	public void increaseRoundsPlayed()
	{
		playedRounds++;
	}
	
	public void calculateWinLoss(int a)
	{
		roundWinnings += a;
		totalWinLoss += a;
		averageWinLoss = totalWinLoss / (playedRounds != 0 ? playedRounds : 1);
	}
	
	public void addRoundStats(int bet, int tempRoundWinnings)
	{
		GameRoundStats tempRoundStat = new GameRoundStats(bet, tempRoundWinnings);
		roundStats.add(tempRoundStat);
		roundWinnings = 0;
	}
	
	public int getRoundWinnings()
	{
		return roundWinnings;
	}
	
	public int getTotalWinLoss()
	{
		return totalWinLoss;
	}
	
	public double getAverageWinLoss()
	{
		return averageWinLoss;
	}
	
	public int getPlayedRounds()
	{
		return playedRounds;
	}
	
	public ArrayList<GameRoundStatsInterface> getRoundStats()
	{
		return new ArrayList<GameRoundStatsInterface>(roundStats);
	}
	
	public String report()
	{
		String report = "played rounds " + playedRounds + " averageWinLoss " + averageWinLoss + " totalWinLoss ";
		
		for (GameRoundStats roundStat: roundStats)
		{
			report += " roundstat bet " + roundStat.getBet() + " roundstat WinLoss " + roundStat.getWinLoss();
		}
		
		return report;
	}
}
